package org.genntii.warehousesystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.genntii.warehousesystem.domain.entity.UserAddress;
import org.genntii.warehousesystem.mapper.UserAddressMapper;
import org.genntii.warehousesystem.service.UserAddressService;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserAddressServiceImpl extends ServiceImpl<UserAddressMapper, UserAddress> implements UserAddressService {

    @Resource
    private UserAddressMapper userAddressMapper;

    @Override
    public void add(int userId, int cityId, String address) {
        UserAddress userAddress = new UserAddress();
        userAddress.setUserId(userId);
        userAddress.setCityId(cityId);
        userAddress.setAddress(address);
        userAddressMapper.insert(userAddress);
    }

    @Override
    public void del(int id) {
        userAddressMapper.deleteById(id);
    }

    @Override
    public List<UserAddress> showAll(int userId) {
        QueryWrapper<UserAddress> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        return userAddressMapper.selectList(wrapper);
    }

    @Override
    public void update(int userId, int cityId, String address, int id) {
        UserAddress u = UserAddress.builder().userId(userId).cityId(cityId).address(address).id(id).build();
        userAddressMapper.updateById(u);
    }

}
